#include <iostream> 
#include <windows.h> 
#include <string.h> 
using namespace std; 

// Forward declaration 
bool Hook(string, HANDLE&); 

int main() 
{ 
	// Put the address you've found inside an int. Don't forget to put 0x before it! 
	// Since we're reading an int, the buffer is an int. The buffer is the place that saves what we're reading 
	int address = (0x400000 + 0x442E444); 
	int buffer = 0; 
	int temp_buffer = 0;

	// Create a handle for direct use and call the hook function 
	HANDLE pHandle; 
	if(!Hook("CoD:United Offensive", pHandle))	// Enter the name and give the variable where our pointer will be stored
		return 1;								// If it failed, return 1

	// Keep checking for change of value. Using while is BAD, but it's fast and works atm
	// Checking should maybe be in the Falcon's ContactCB()
	while(1)
	{
		// Set the temp buffer to the current buffer, to compare the old value with the new value
		temp_buffer = buffer;

		// Call the ReadProcessMemory function. More info @ http://msdn.microsoft.com/en-us/library/ms680553(VS.85).aspx
		ReadProcessMemory(pHandle, (int*)(address), &buffer, sizeof(int), 0); 
		
		// Output the buffer, the new value, after we've confirmed it got decreased by 1
		if(temp_buffer == (buffer + 1))
			cout << buffer << endl; 
			// Falcon_GunIsFired();
	}

	return 0; 
} 

bool Hook(string name, HANDLE& pHandle) 
{ 
	// Create a variable for the Process ID (To know which process we're reading from) 
	// Next find the hWnd by name, using the FindWindow function. 
	DWORD pid; 
	HWND hWnd = FindWindow(NULL, name.c_str()); 

	if(!hWnd) 
	{ 
		cout << "Window \"" << name.c_str() << "\" not found!" << endl;
		cin.get();
		return 0;
	} 
	else 
	{ 
		// Get the Process ID of the process whose hWnd we have found. 
		// Next, open up the proccess with all access. A pointer to the handle is given, ready for reading! 
		GetWindowThreadProcessId(hWnd,&pid); 
		if((pHandle = OpenProcess(PROCESS_ALL_ACCESS, 0, pid)) != NULL)
		{
			cout << "Successfully opened process: " << pid << endl;
			return 1;
		}
		else
		{
			cout << "Failed to open process: " << pid << endl;
			return 0;
		}
	} 
}
